<template>
  <div v-show="visible" class="guide-step-dialog" :class="{ is_end: step > steps }" :style="{ ...position }">
    <template v-if="step <= steps">
      <i
        v-if="stepInfo.iconInfo"
        :class="['arrow-icon', stepInfo.iconInfo.icon]"
        :style="{ ...stepInfo.iconInfo.style }"></i>
      <div class="guide-step-title">
        {{ stepInfo.title }}
        <span>（{{ step }}/{{ steps }}）</span>
      </div>
      <div class="guide-step-content">
        <!-- <div class="con-left">
          <img src="../assets/images/svgs/guide-step.svg" alt="" />
        </div> -->
        <div class="con-right">
          <p class="guide-step-desc">{{ stepInfo.desc }}</p>
          <div class="btn-box">
            <template v-if="step < steps">
              <el-button size="small" type="primary" @click.stop="nextStep">下一步</el-button>
              <el-button type="text" @click.stop="closeStep">跳过指引</el-button>
            </template>
            <el-button v-else size="small" type="primary" @click.stop="nextStep" class="complete-btn">完成</el-button>
          </div>
        </div>
      </div>
    </template>
    <template v-else>
      <div class="guide-step-end">
        <div class="guide-step-title center">恭喜！完成所有学习指引~</div>
        <div class="guide-step-content success-content center">
          <img src="../assets/images/svgs/guide-end.svg" alt="" class="success-img" />
        </div>
        <div class="btn-box center">
          <el-button type="primary" size="small" @click.stop="closeStep">开始使用</el-button>
          <el-button type="text" @click.stop="restartStep">重新学习</el-button>
        </div>
      </div>
    </template>
  </div>
</template>
<script>
export default {
  name: 'guideStep',
  emits: ['close-step', 'next-step', 'restart-step'],
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    info: {
      type: Object,
      default: () => {},
    },
    position: {
      type: Object,
      default: () => {},
    },
    step: {
      type: Number,
      default: 1,
    },
    steps: {
      type: Number,
      default: 5,
    },
  },
  data() {
    return {
      stepInfo: {},
    }
  },
  watch: {
    info: {
      handler(obj) {
        if (obj && obj.step) {
          this.stepInfo = obj
        }
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    closeStep() {
      this.$emit('close-step', false)
    },
    nextStep() {
      this.$emit('next-step', this.step + 1)
    },
    restartStep() {
      this.$emit('restart-step', 1)
    },
  },
}
</script>
<style lang="scss" scoped>
.guide-step-dialog {
  position: absolute;
  z-index: 100;
  width: 400px;
  // height: 260px;
  min-height: 200px;
  padding: 15px 25px;
  border-radius: 10px;
  background-color: #fff;
  box-shadow: 5px 5px 5px rgba(100, 100, 100, 0.3);
  .arrow-icon {
    position: absolute;
    font-size: 48px;
    color: #2b78f1;
  }
  .guide-step-title {
    text-align: left;
    font-size: 15px;
    color: #2b78f1;
    margin-bottom: 10px;
    font-size: 26px;
    font-weight: bold;
    line-height: 34px;
    span {
      font-weight: normal;
      font-size: 20px;
    }
  }
  .guide-step-content {
    width: 100%;
    display: flex;
    align-items: flex-start;
    .con-left {
      width: 140px;
      height: 100%;
      img {
        display: inline-block;
        width: 100%;
        position: relative;
        transform: translateY(50%);
      }
    }
    .con-right {
      flex: 1;
    }
    .guide-step-desc {
      font-size: 14px;
      color: #333;
      line-height: 28px;
      margin-bottom: 20px;
    }
    .btn-box {
      // text-align: center;
      .el-button {
        font-size: 13px;
      }
      .el-button + .el-button {
        margin-left: 30px;
      }
      .complete-btn {
        margin-top: 20px;
        padding: 10px 25px;
      }
      .el-button--text {
        text-decoration: underline;
      }
    }
  }
  .guide-step-end {
    display: flex;
    flex-direction: column;
    align-items: center;
    .center {
      text-align: center;
    }
    .guide-step-title {
      font-size: 16px;
    }
    .success-content {
      margin-bottom: 20px;
    }
    .success-img {
      display: block;
      width: 140px;
      margin: 0 auto;
      height: auto;
    }
    .btn-box {
      display: flex;
      flex-direction: column;
      align-items: center;
      .el-button {
        margin: 0;
        font-size: 14px;
      }
      .el-button--text {
        margin-top: 10px;
        color: #666;
      }
    }
  }
}
</style>
